App.module.Language.Code.Delete = Ext.extend(Ext.util.Observable, {
	init: function(grid){
		this.grid = grid;
		
		grid.on('render', function(grid){
			
			var bt = new Ext.Button({
				tooltip: 'Delete'
				,iconCls: 'icon-delete-16x16'
				,disabled: true
				,scope: this
				,handler: this.del
			}, this);
			
			grid.getTopToolbar().add(bt);
			grid.selModel.on('selectionchange', function(sm){
				bt.setDisabled( !sm.hasSelection() );	
			});
				
		}, this);
	}
	
	,del: function(){
		if(!this.grid.selModel.hasSelection()) return;
		
		Ext.Msg.confirm('Delete', 'Do you want to delete?', function(bt){
			if('no' == bt) return;
			
			var rec = this.grid.selModel.getSelections();
			var ids = [];
			
			for(var i = 0, len = rec.length; i < len; ++i){
				ids.push(rec[i].data.id);
			}
			
			this.grid.getStore().remove(rec);
			
			API.language.delCode({ids: ids}, function(r){
				
			});
			
		}, this);
	}
});